<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>角色列表--CRM客户关系管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="resources/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="resources/css/public.css" media="all"/>
</head>
<body class="childrenBody">
<table id="roleList" lay-filter="roleList"></table>
<!--操作-->
<script type="text/html" id="roleListBar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">查看</a>
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="assignRight">分配权限</a>
</script>
<script type="text/javascript" src="resources/layui/layui.js"></script>
<script type="text/javascript" th:inline="none">
    layui.use(['form', 'layer', 'table', 'laytpl'], function () {
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laytpl = layui.laytpl,
            table = layui.table;
        //用户列表
        var tableIns = table.render({
            elem: '#roleList',
            url: 'roles.do',
            cellMinWidth: 95,
            page: true,
            height: "full-200",
            limits: [10, 15, 20, 25],
            limit: 30,
            id: "roleListTable",
            cols: [[
                {type: "checkbox", fixed: "left", width: 50},
                {field: 'id', title: '编号', minWidth: 100, align: "center"},
                {field: 'rolename', title: '角色名', align: 'center'},
                {title: '操作', minWidth: 175, templet: '#roleListBar', fixed: "right", align: "center"}
            ]]
        });
        table.on("tool(roleList)", function (obj) {
            //获取当前行的数据
            var data = obj.data;
            switch (obj.event) {
                case 'assignRight':
                    assignRight(data);
                    break;
            }
        });

        function assignRight(data) {
            var assignRightIndex = layer.open({
                type: 2,
                title: "分配权限",
                content: "/toAssignRight.do",
                area: ['350px', '350px'],
                success: function (layero, index) {
                    var body = layer.getChildFrame('body', index);//少了这个是不能从父页面向子页面传值的
                    body.contents().find("#roleIdHiden").val(data.id);//这样就将值传递给子页面中id为userIdHiden的隐藏域
                }
            });
            window.sessionStorage.setItem("assignRightIndex", assignRightIndex);
            //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
            $(window).on("resize", function () {
                layui.layer.full(window.sessionStorage.getItem("index"));
            })
        }
    });
</script>
</body>
</html>